package tk.paulista.dc.control;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;

import tk.paulista.dc.model.Usuario;


public abstract class ApplicationAbstractController {

	protected Usuario getUsuarioLogado() {
		return Usuario.findUsuariosByNomeDoUsuarioEquals(((User) SecurityContextHolder
						.getContext()
						.getAuthentication()
						.getPrincipal())
						.getUsername()).getSingleResult();
	}

	protected Date getDateWithoutTime() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return sdf.parse(sdf.format(new Date()));
		} catch (ParseException e) {
			throw new RuntimeException(e);
		}
	}



	

}
